package com.zqxx.examine.portal.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zqxx.examine.common.utils.Page;
import com.zqxx.examine.model.training.Training;
import com.zqxx.examine.model.training.TrainingSection;
import com.zqxx.examine.model.training.TrainingSectionProcess;
import com.zqxx.examine.model.training.UserTrainingHistory;
import com.zqxx.examine.portal.persistence.TrainingMapper;

@Service 
public class   TrainingService
{
  @Autowired
  private TrainingMapper trainingMapper;
  
  public List<Training> getTrainingList(Page<Training> page)
  {
    return this.trainingMapper.getTrainingList(page);
  }
  
  public List<TrainingSection> getTrainingSectionByTrainingId(int trainingId, Page<TrainingSection> page)
  {
    return this.trainingMapper.getTrainingSectionByTrainingId(trainingId, page);
  }
  
  public List<TrainingSection> getTrainingSectionById(int sectionId, Page<TrainingSection> page)
  {
    return this.trainingMapper.getTrainingSectionById(sectionId, page);
  }
  
  public UserTrainingHistory getTrainingHistBySectionId(int sectionId, int userId)
  {
    return this.trainingMapper.getTrainingHistBySectionId(sectionId, userId);
  }
  
  public void setUserTrainingHistory(UserTrainingHistory hist)
  {
    this.trainingMapper.setUserTrainingHistory(hist);
  }
  
  public Map<Integer, List<TrainingSectionProcess>> getTrainingSectionProcessMapByUserId(int userId)
  {
    List<TrainingSectionProcess> processList = this.trainingMapper.getTrainingSectionProcessListByUserId(userId, null);
    HashMap<Integer, List<TrainingSectionProcess>> map = new HashMap();
    for (TrainingSectionProcess process : processList)
    {
      List<TrainingSectionProcess> tmpList = new ArrayList();
      if (map.containsKey(Integer.valueOf(process.getTrainingId()))) {
        tmpList = (List)map.get(Integer.valueOf(process.getTrainingId()));
      }
      tmpList.add(process);
      map.put(Integer.valueOf(process.getTrainingId()), tmpList);
    }
    return map;
  }
}
